﻿using System.ComponentModel;
using Loki.UI;
using Loki.Utils;
using Luna.Model;

namespace Luna.UI
{
    public abstract class LunaViewModel : ViewModel<IApplicationModel>
    {
        private static PropertyChangedEventArgs _FullNameChangedArgs = ObservableHelper.CreateChangedArgs<LunaViewModel>(x => x.FullDisplayName);

        public LunaViewModel()
        {
            this.WatchChange(this, x => x.DisplayName, c => c.DisplayName_Changed);
        }

        public override string FullDisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(GroupName))
                {
                    return base.FullDisplayName;
                }
                else
                {
                    return string.Format("{0} - {1}", GroupName, DisplayName);
                }
            }
        }

        private void DisplayName_Changed(object sender, System.EventArgs e)
        {
            NotifyChanged(_FullNameChangedArgs);
        }

        #region GroupName

        private static PropertyChangedEventArgs _GroupNameChangedArgs = ObservableHelper.CreateChangedArgs<LunaViewModel>(x => x.GroupName);

        private static PropertyChangingEventArgs _GroupNameChangingArgs = ObservableHelper.CreateChangingArgs<LunaViewModel>(x => x.GroupName);

        private string _GroupName;

        public string GroupName
        {
            get
            {
                return _GroupName;
            }

            set
            {
                if (value != _GroupName)
                {
                    NotifyChanging(_GroupNameChangingArgs);
                    _GroupName = value;
                    NotifyChanged(_GroupNameChangedArgs);
                }
            }
        }

        #endregion GroupName
    }
}